package jaegersvc

import (
	"errors"
	"github.com/spf13/viper"
	"gluenet/internal/agent/depend"
	"gluenet/internal/agent/driver"
	v1 "gluenet/pkg/log/v1"
)

func init() {
	depend.Provide(NewJaegerConfig)
	depend.Provide(NewService)
}

type Service struct {
	logger    v1.Logger
	jaegerCfg *JaegerConfig
}

func NewService(jaegerCfg *JaegerConfig) *Service {
	return &Service{
		logger:    v1.NewLogger(""),
		jaegerCfg: jaegerCfg,
	}
}

const (
	keyJaegerAddr = driver.KeyDriverPerfix + `jaeger.addr`
)

type JaegerConfig struct {
	Addr string
}

func NewJaegerConfig(vp *viper.Viper) (*JaegerConfig, error) {
	addr := vp.GetString(keyJaegerAddr)
	if addr == "" {
		return nil, errors.New("empty jaeger addr")
	}
	return &JaegerConfig{
		Addr: addr,
	}, nil
}
